package org.example.projectdemo.model.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import jakarta.persistence.*;
import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Pattern;
import jakarta.validation.constraints.Size;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.ColumnDefault;

import java.time.LocalDateTime;

@Getter
@Setter
@Entity
@Table(name = "student", schema = "projectfrist")
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
public class Student {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", nullable = false)
    private Long id;

    @NotBlank(message = "学号不能为空")
    @Size(max = 20, message = "学号长度不能超过20个字符")
    @Column(name = "student_number", nullable = false, length = 20)
    private String studentNumber;

    @NotBlank(message = "学生姓名不能为空")
    @Column(name = "student_name", nullable = false)
    private String studentName;

    @NotBlank(message = "班级名称不能为空")
    @Column(name = "class_name", nullable = false)
    private String className;

    @NotBlank(message = "手机号不能为空")
    @Pattern(regexp = "^1[3-9]\\d{9}$", message = "手机号格式不正确")//第二位除数字2之外的其他数字，防止一些无效的号码：123456789...
    @Column(name = "phone", nullable = false, length = 20)
    private String phone;

    @NotBlank(message = "邮箱不能为空")
    @Email(message = "邮箱格式不正确")
    @Column(name = "email", nullable = false)
    private String email;

    @ColumnDefault("1")
    @Column(name = "state")
    private Byte state;

    // 软删除字段
    @Column(name = "deleted")
    @JsonIgnore
    private Boolean deleted = false;
    
    // 删除时间字段
    @Column(name = "deleted_at")
    @JsonIgnore
    private LocalDateTime deletedAt;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "user_id")
    @JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
    private User user;

}